

; ------------------------------------------------------------------------

; 显示 AL 中的数字

; ------------------------------------------------------------------------

DispAL:

	push	ecx

	push	edx

	push	edi



	mov	edi, [dwDispPos]



	mov	ah, 0Fh			; 0000b: 黑底    1111b: 白字

	mov	dl, al

	shr	al, 4

	mov	ecx, 2

.begin:

	and	al, 01111b

	cmp	al, 9

	ja	.1

	add	al, '0'

	jmp	.2

.1:

	sub	al, 0Ah

	add	al, 'A'

.2:

	mov	[gs:edi], ax

	add	edi, 2



	mov	al, dl

	loop	.begin

	;add	edi, 2



	mov	[dwDispPos], edi



	pop	edi

	pop	edx

	pop	ecx



	ret

; DispAL 结束-------------------------------------------------------------





; ------------------------------------------------------------------------

; 显示一个整形数

; ------------------------------------------------------------------------

DispInt:

	mov	eax, [esp + 4]

	shr	eax, 24

	call	DispAL



	mov	eax, [esp + 4]

	shr	eax, 16

	call	DispAL



	mov	eax, [esp + 4]

	shr	eax, 8

	call	DispAL



	mov	eax, [esp + 4]

	call	DispAL



	mov	ah, 07h			; 0000b: 黑底    0111b: 灰字

	mov	al, 'h'

	push	edi

	mov	edi, [dwDispPos]

	mov	[gs:edi], ax

	add	edi, 4

	mov	[dwDispPos], edi

	pop	edi



	ret

; DispInt 结束------------------------------------------------------------



; ------------------------------------------------------------------------

; 显示一个字符串

; ------------------------------------------------------------------------

DispStr:

	push	ebp

	mov	ebp, esp;取得此时的堆栈指针

	push	ebx

	push	esi

	push	edi



	mov	esi, [ebp + 8]	; pszInfo,因为之前push过ebp，所以现在是+8

	mov	edi, [dwDispPos]

	mov	ah, 0Fh

.1:

	lodsb

	test	al, al

	jz	.2

	cmp	al, 0Ah	; 是回车吗?

	jnz	.3

	push	eax

	mov	eax, edi

	mov	bl, 160

	div	bl

	and	eax, 0FFh

	inc	eax

	mov	bl, 160

	mul	bl

	mov	edi, eax

	pop	eax

	jmp	.1

.3:

	mov	[gs:edi], ax

	add	edi, 2

	jmp	.1



.2:

	mov	[dwDispPos], edi



	pop	edi

	pop	esi

	pop	ebx

	pop	ebp

	ret

; DispStr 结束------------------------------------------------------------



; ------------------------------------------------------------------------

; 换行

; ------------------------------------------------------------------------

DispReturn:

	push	szReturn

	call	DispStr			;printf("\n");

	add	esp, 4



	ret

; DispReturn 结束---------------------------------------------------------


; ------------------------------------------------------------------------

; 内存拷贝，仿 memcpy

; ------------------------------------------------------------------------

; void* MemCpy(void* es:pDest, void* ds:pSrc, int iSize);
;参数都依次被压入在堆栈中
;使用ax作为返回数值：目标地址偏移
; ------------------------------------------------------------------------

MemCpy:
	push	ebp
	mov	ebp, esp; 取得此时堆栈指针
	push	esi
	push	edi
	push	ecx
	push	eax

	mov	edi, [ebp + 8]	; Destination
	mov	esi, [ebp + 12]	; Source
	mov	ecx, [ebp + 16]	; Counter
.loop:
	cmp	ecx,0
	jz	.Done
	mov	al,[ds:esi]
	mov	[es:edi],al
	inc	esi
	inc	edi
	sub	ecx,1
	jmp	.loop
.Done:
	pop	eax
	pop	ecx
	pop	edi
	pop	esi
	mov	esp, ebp
	pop	ebp

	ret			; 函数结束，返回

; MemCpy 结束-------------------------------------------------------------

